class Solution:
    def maxAreaOfIsland(self, grid: List[List[int]]) -> int:
        if not grid or not grid[0]:
            return 0
        m=len(grid)
        n=len(grid[0])
        res=0
        for i in range(m):
            for j in range(n):
                if grid[i][j] == 1:
                    b=collections.deque([[i,j]])
                    grid[i][j] = 2 
                    val = 0
                    while b:
                        x,y=b.popleft()
                        val+=1
                        for k1, k2 in [(x+1,y),(x-1,y), (x, y+1), (x, y-1)]:
                            if 0<=k1<m and 0 <= k2 < n and grid[k1][k2] == 1:
                                grid[k1][k2] = 2
                                b.append([k1,k2])
                    res=max(res,val)
        return res